import { Gain } from "../../../../info/GameEnum";
import { AiEnvironment } from "../../AiGameAction";
import { DecisionNode } from "../../DecisionTree";

/**
 * 升级攻击
 */
export default class DecisionAttactUpgrade extends DecisionNode {

    environment: AiEnvironment & {
        condition: {
            shellHealth: number;
            shellPower: number;
            shellRange: number;
        };
    };
    shellHealth: number;
    shellPower: number;
    shellRange: number;

    constructor(environment: any) {
        super(environment);
        this.childDecisionNodes.push(new DecisionAttactUpgradeShellHealth(environment));
        this.childDecisionNodes.push(new DecisionAttactUpgradeShellPower(environment));
        this.childDecisionNodes.push(new DecisionAttactUpgradeShellRange(environment));
    }

    evaluate(): number {
        this.shellHealth = 0;
        this.shellPower = 0;
        this.shellRange = 0;
        if (this.environment.gainFeasibility.get(Gain.炮弹血量升级).every(item => item)) {
            this.shellHealth = 20;
        }
        if (this.environment.gainFeasibility.get(Gain.炮弹攻击力升级).every(item => item)) {
            this.shellPower = 20;
        }
        if (this.environment.gainFeasibility.get(Gain.炮弹射程升级).every(item => item)) {
            this.shellRange = 20;
        }
        return this.shellHealth + this.shellPower + this.shellRange;
    }

    execute(): number {
        this.environment.condition = {
            shellHealth: this.shellHealth,
            shellPower: this.shellPower,
            shellRange: this.shellRange
        }
        return super.execute();
    }

}

/**
 * 炮弹血量升级
 */
class DecisionAttactUpgradeShellHealth extends DecisionNode {

    environment: AiEnvironment & {
        condition: {
            shellHealth: number;
            shellPower: number;
            shellRange: number;
        };
    };
    evaluate(): number {
        return this.environment.condition.shellHealth;
    }

    execute(): number {
        this.environment.player.shellHealthBonusLevelUp();
        return 0;
    }
}

/**
 * 炮弹攻击力升级
 */
class DecisionAttactUpgradeShellPower extends DecisionNode {
    environment: AiEnvironment & {
        condition: {
            shellHealth: number;
            shellPower: number;
            shellRange: number;
        };
    };
    evaluate(): number {
        return this.environment.condition.shellPower;
    }

    execute(): number {
        this.environment.player.shellDamageBonusLevelUp();
        return 0;
    }
}
/**
 * 炮弹射程升级
 */
export class DecisionAttactUpgradeShellRange extends DecisionNode {
    environment: AiEnvironment & {
        condition: {
            shellHealth: number;
            shellPower: number;
            shellRange: number;
        };
    };
    evaluate(): number {
        return this.environment.condition.shellRange;
    }

    execute(): number {
        this.environment.player.shellRangeBonusLevelUp();
        return 0;
    }
}